const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const merge = require("webpack-merge");
const webpackBaseConfig = require("./webpack.base.config.js");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const fs = require("fs");
const config = require("./config.json");
var path = require("path");

module.exports = merge(webpackBaseConfig, {
  output: {
    publicPath: "",
    filename: "[name].[hash:8].js",
    chunkFilename: "[name].[hash:8].js"
  },
  plugins: [
    new ExtractTextPlugin({
      filename: "[name].[hash:8].css",
      allChunks: true
    }),
    new webpack.DefinePlugin({
      "process.env": {
        NODE_ENV: '"production"'
      },
      appConfig: {
        API: JSON.stringify(config["prd"])
      }
    }),
    new webpack.optimize.CommonsChunkPlugin({
      name: "vendors",
      filename: "vendors.[hash:8].js"
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false,
        drop_console: true
      }
    }),
    new HtmlWebpackPlugin({
      configUrl: "./config.js?v=" + Date.now(),
      favicon: "./favicon.ico",
      filename: "./index.html",
      template: "./src/template/index.ejs",
      inject: true
    }),
    new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, "../static"),
        to: "static",
        ignore: [".*"]
      }
    ])
  ]
});
